<?php 
/*
function mysort($a, $b)
{
    return intval($a['name']) > intval($b['name']);
}

$data = array('1' => array('name' => '7'), '2' => array('name' => '9'), '3' => array('name' => '6'),);

usort($data, "mysort");

foreach ($data as $key => $value) {
	echo "$key: {$value['name']}\n";
}

*/

//hhelo
class SampleDI
{	
	public static $_stores = array();
	
	/**
	 * @var Inject('db', 'singleton' = 1)
	 */
	private $_name = '123';
	
	public function __construct()
	{
		$inject = new Inject();
		$inject->value = 'db';
		
		self::$_stores['_name'] = $inject;
		
		unset($this->_name);
	}
	
	public function getName()
	{
		return $this->_name;
	}
	
	public function __get($key)
	{
		if(isset(self::$_stores[$key]))
		{
			return self::$_stores[$key]->instance();
		}
		return $key;
	}
}

$sampleDI = new SampleDI();
echo '<pre>';
print_r($sampleDI->getName());
echo '</pre>';

class SamplePro
{
	public function hello()
	{
		echo 'Hello world';
	}
}

class Inject
{
	/**
	 * Bean value
	 * @var string
	 */
	public $value;

	public function instance()
	{
		return $this->value;
	}
}

class Sample
{
	private static $_store = array();
	
	/**
	 * @var Inject('db')
	 */
	private $_sample1 = '123';
	
	/**
	 * @var Inject('SamplePro')
	 */
	protected $_sample2 = '456';
	
	public $sample3 = '789';
	
	public function __get($key)
	{
		return isset(self::$_store[$key]) ? self::$_store[$key]->instance() : null;
	}
	
	public function getSample1()
	{
		return $this->_sample1;
	}
	
	public function reflection()
	{
		$reflectionClass = new ReflectionClass('Sample');
		
		$properties = $reflectionClass->getProperties();
		
		foreach ($properties as $property)
		{
			$propertyName = $property->getName();
		
			$reflectionProperty = new ReflectionProperty('Sample', $propertyName);
		
			$propertyComment = $reflectionProperty->getDocComment();
		
			$pattern = '/[^a-z0-9\s@\'\(\)]/i';
			$filtered = preg_replace($pattern, '', $propertyComment);
		
		
			$pattern = '/inject\(\'([a-z0-9]+)\'\)/i';
			preg_match($pattern, $filtered, $matches);
		
			if (! empty($matches))
			{
				$inject = new Inject();
				$inject->value = $matches[1];
		
				self::$_store[$propertyName] = $inject;
				
				unset($this->{$propertyName});
			}
		}
	}
}

$sample = new Sample();
$sample->reflection();

echo $sample->getSample1();

echo '<pre>';
print_r($sample);
echo '</pre>';